package com.zrwl.poscloud.core.restapi.demo;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.Delete;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.commons.validator.group.Update;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.xo.service.DemoService;
import com.zrwl.poscloud.xo.vo.DemoVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 演示 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2022-09-05
 */
@RestController
@Api(value = "演示相关接口", tags = {"演示相关接口"})
@RequestMapping("/demo")
@Slf4j
public class DemoRestApi {
    @Autowired
    private DemoService demoService;
    @AuthorityVerify
    @ApiOperation(value = "获取演示列表", notes = "获取演示列表", response = String.class)
    @PostMapping("/getList")
    public String getList(@Validated({GetList.class}) @RequestBody DemoVO demoVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取演示列表: {}", demoVO);
        return ResultUtil.successWithData(demoService.getPageList(demoVO));
    }

    @AuthorityVerify
    @ApiOperation(value = "获取演示列表", notes = "获取演示列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody DemoVO demoVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取演示列表: {}", demoVO);
        return ResultUtil.successWithData(demoService.getAllList(demoVO));
    }

    @AuthorityVerify
    @OperationLogger(value = "新增演示")    @ApiOperation(value = "新增演示", notes = "新增演示", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody DemoVO demoVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增演示: {}", demoVO);
        return demoService.add(demoVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "修改演示")    @ApiOperation(value = "修改演示", notes = "修改演示", response = String.class)
    @PostMapping("/edit")
    public String edit(@Validated({Update.class}) @RequestBody DemoVO demoVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("修改演示: {}", demoVO);
        return demoService.edit(demoVO);
    }

    @AuthorityVerify
    @OperationLogger(value = "删除演示")    @ApiOperation(value = "删除演示", notes = "删除演示", response = String.class)
    @PostMapping("/delete")
    public String delete(@Validated({Delete.class}) @RequestBody DemoVO demoVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("删除演示: {}", demoVO);
        return demoService.delete(demoVO);
    }

}
